package com.psychology.Enum;

import cn.hutool.core.util.StrUtil;


public enum RoleEnum {
    USER("USER", "普通用户"),
    PSYCHOLOGIST("PSYCHOLOGIST", "心理医生"),
    ADMIN("ADMIN", "管理员");

    private String code;
    private String name;

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    RoleEnum(String code, String description) {
        this.code = code;
        this.name = description;
    }

    public static String getName(String code) {
        if (StrUtil.isEmptyIfStr(code)) {
            return null;
        }

        for (RoleEnum c : RoleEnum.values()) {
            if (code.equals(c.getCode())) {
                return c.name;
            }
        }
        return null;
    }

    public static String getCode(String name) {
        if (StrUtil.isEmptyIfStr(name)) {
            return null;
        }

        for (RoleEnum c : RoleEnum.values()) {
            if (name.equals(c.getName())) {
                return c.code;
            }
        }
        return null;
    }
}

